<?php
    #-------------------------------------------------------------#
	# This file is part of the Kumomado - Virtual Window Platform #
	# for PHP. (c) 2009 Tsai, Min Che <tirme0812@gmail.com>       #
	# Please visit http://www.kumomado.org/ for more information. #
	#                                                             #
	# This software is licensed under the GNU License v3. Please  #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#

	Kumomado::load('Kui.KumomadoAbstractComponent');
	/**
	 * @package libraries/kui/components/datagrid/
	 * @author Tsai, Min Che
	 * @version 1.0
	 */
	class KumomadoDataGrid extends KumomadoAbstractComponent {
		protected $ui_name = 'DataGrid';
		protected $template_file = 'DataGrid.xsl';
		protected $columns = array();
		protected $rows = array();
		public function __construct($id) {
			$this->id = $id;
		}
		public function setColumns($columns) {
			$this->columns = (array)$columns;
		}
		public function addRow($data, $row = 0) {
			if ($row == 0) {
				array_unshift($this->rows, $data);
			} else {
				array_splice($this->rows, $row, 0, $data);
			}
		}
		public function addRows($data, $row = 0) {
			if ($row == 0) {
				$this->rows = array_merge($data, $this->rows);
			} else {
				array_splice($this->rows, $row, 0, $data);
			}
		}
		protected function view() {
			Kumomado::load('Xml.KumomadoXsltProcessor');
			$xslt = new KumomadoXsltProcessor();
			$xslt->importArray(array('id' => $this->id, 'Columns' => $this->columns, 'Rows' => $this->data));
			$xslt->importStyleSheet(dirname(__FILE__).DIRECTORY_SEPARATOR.$this->template_file);
			return $xslt->transformToDoc();
		}
		public function render() {
			return array(
				'ui_name' => $this->ui_name,
				'view' => $this->view()
			);
		}
	}
?>